/**
 * Copyright 2016 JustWayward Team
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.zhuike.novel.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import net.zhuike.novel.app.R;
import net.zhuike.novel.app.bean.CategoryList;
import net.zhuike.novel.app.bean.TabModel;
import net.zhuike.novel.app.common.OnRvItemClickListener;
import java.util.List;

import framework.common.easyadpter.recyclerview.EasyRVAdapter;
import framework.common.easyadpter.recyclerview.EasyRVHolder;

/**
 * @author wq.
 * @date 17/6/21.
 */
public class TopCategoryListAdapter extends BaseAdapter {
    private OnRvItemClickListener itemClickListener;
    private Context mContext;
    public  List<TabModel> data;
    private LayoutInflater layoutInflater;
    private OnRecyclerViewItemListener mOnRecyclerViewItemListener;

    public void setOnRecyclerViewItemListener(OnRecyclerViewItemListener listener) {
        mOnRecyclerViewItemListener = listener;
    }

    public TopCategoryListAdapter(Context mContext, List<TabModel> list, OnRvItemClickListener listener) {
        this.mContext = mContext;
        this.data = list;
        layoutInflater = LayoutInflater.from(mContext);
        this.itemClickListener = listener;
    }
    class ViewHolder {
        TextView tvName;
        TextView tvBookCount;

    }
    public interface OnRecyclerViewItemListener {
        public void onItemClickListener(int position);

    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_top_category_list, null);
            holder.tvName = (TextView) convertView
                    .findViewById(R.id.tvName);
            holder.tvBookCount= (TextView) convertView
                    .findViewById(R.id.tvBookCount);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (mOnRecyclerViewItemListener != null) {
            mOnRecyclerViewItemListener.onItemClickListener( position);
        }
        TabModel item=data.get(position);
        holder.tvName.setText(item.getName());
        return convertView;
    }
}
